package com.smedi.ismedi.constructionproject.core.port.adapter.service.impl;


import com.smedi.ismedi.constructionproject.core.application.command.ProcessInstanceStartCommand;
import com.smedi.ismedi.constructionproject.core.application.command.ProcessTaskCompleteCommand;
import com.smedi.ismedi.constructionproject.core.application.command.ProcessTaskListCommand;
import com.smedi.ismedi.constructionproject.core.domain.aggregatemodel.ProcessTask;
import com.smedi.ismedi.constructionproject.core.port.adapter.restful.convert.AdapterConverter;
import com.smedi.ismedi.constructionproject.core.port.adapter.service.ProcessRemoteService;
import com.smedi.ismedi.inmail.api.dto.request.ProcessInstanceStartRequest;
import com.smedi.ismedi.inmail.api.dto.request.ProcessTaskCompleteRequest;
import com.smedi.ismedi.inmail.api.dto.request.ProcessTaskListRequest;
import com.smedi.ismedi.inmail.api.dto.response.ProcessTaskResponse;
import com.smedi.ismedi.inmail.api.feign.RemoteProcessFeignApi;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@AllArgsConstructor
public class ProcessRemoteServiceImpl implements ProcessRemoteService {

    private final RemoteProcessFeignApi remoteProcessFeignApi;

    private final AdapterConverter adapterConverter;

    @Override
    public ProcessTask startProcessInstance(ProcessInstanceStartCommand processInstanceStartCommand) {
        ProcessInstanceStartRequest processInstanceStartRequest = adapterConverter.processInstanceStartCommandToProcessInstanceStartRequest(processInstanceStartCommand);
        ProcessTaskResponse processTaskResponse = remoteProcessFeignApi.startProcessInstance(processInstanceStartRequest).getData();
        return adapterConverter.processTaskResponseToProcessTask(processTaskResponse);
    }

    @Override
    public ProcessTask completeProcessTask(ProcessTaskCompleteCommand processTaskCompleteCommand) {
        ProcessTaskCompleteRequest processTaskCompleteRequest = adapterConverter.processTaskCompleteCommandToProcessTaskCompleteRequest(processTaskCompleteCommand);
        ProcessTaskResponse processTaskResponse = remoteProcessFeignApi.completeProcessTask(processTaskCompleteRequest).getData();
        return adapterConverter.processTaskResponseToProcessTask(processTaskResponse);
    }

    @Override
    public List<ProcessTask> getProcessTaskList(ProcessTaskListCommand processTaskListCommand) {
        ProcessTaskListRequest processTaskListRequest = adapterConverter.processTaskListCommandToProcessTaskListRequest(processTaskListCommand);
        List<ProcessTaskResponse> processTaskResponses = remoteProcessFeignApi.getProcessTaskList(processTaskListRequest).getData();
        return adapterConverter.processTaskResponsesToProcessTasks(processTaskResponses);
    }
}
